package com.oazon.moco.link.ui;

import java.util.Arrays;
import java.util.List;

import android.util.Log;

import com.oazon.moco.bean.PlayStatus;
import com.oazon.moco.lan.core.http.bean.AllSatus;
import com.oazon.moco.lan.core.http.bean.AllStateInstance;
import com.oazon.moco.lan.core.http.bean.MediaStateInstance;
import com.oazon.moco.lan.core.http.bean.PositionInfo;
import com.oazon.moco.lan.core.http.bean.ResponseVolume;
import com.oazon.moco.lan.core.http.bean.SongInfo;
import com.oazon.moco.lan.core.http.bean.ZoneInfo;
import com.oazon.moco.link.core.LinkEvent;
import com.oazon.moco.link.core.LinkEventListener;
import com.oazon.moco.link.core.LinkSDK;
import com.oazon.moco.link.core.source.LinkEventSource;
import com.oazon.moco.link.event.RequestEvent;
import com.oazon.moco.link.event.RequestStatus;

public class RequestEventListener extends LinkEventListener {

	private static final String TAG = "RequestEventListener";

	public RequestEventListener(LinkEventSource... source) {
		setBlackList(Arrays.asList(source));
	}
	
	@Override
	public void onLinkEvent(LinkEvent event) {
		if (filter((LinkEventSource)event.getSource())	|| !(event instanceof RequestEvent)) {
			return;
		}

		RequestEvent requestEvent = (RequestEvent) event;

		if (requestEvent.getRequestStatus() == RequestStatus.VERSION) {
			LinkSDK.getInstance()
					.responseVersion(
							(LinkEventSource) requestEvent.getSource(),
							getVersion(requestEvent.getZoneInfo()));
		}else if (requestEvent.getRequestStatus() == RequestStatus.PLAY_STATUS) {
			LinkSDK.getInstance()
					.responsePlayStatus(
							(LinkEventSource) requestEvent.getSource(),
							getPlayStatus());
		}else if(requestEvent.getRequestStatus() == RequestStatus.PROGRESS) {
			LinkSDK.getInstance()
					.responsePositionInfo(
							(LinkEventSource) requestEvent.getSource(),
							getPositionInfo(requestEvent.getInstanceID()));
		}else if(requestEvent.getRequestStatus() == RequestStatus.VOLUME) {
			LinkSDK.getInstance()
					.responseVolume(
							(LinkEventSource) requestEvent.getSource(),
							getVolume(requestEvent.getInstanceID()));
		}else if(requestEvent.getRequestStatus() == RequestStatus.SONG_INFO) {
			LinkSDK.getInstance()
					.responseSongInfo(
							(LinkEventSource) requestEvent.getSource(),
							getSongInfo());
		}else if(requestEvent.getRequestStatus() == RequestStatus.CATEGORY) {
			LinkSDK.getInstance()
					.responseCategory(
							(LinkEventSource) requestEvent.getSource(),
							getCategory());
		}else if(requestEvent.getRequestStatus() == RequestStatus.PLAY_MODE) {
			LinkSDK.getInstance()
					.responsePlayMode(
							(LinkEventSource) requestEvent.getSource(),
							getPlayMode());
		}else if(requestEvent.getRequestStatus() == RequestStatus.ALL_STAUS) {
			LinkSDK.getInstance()
					.responseAllStatus(
							(LinkEventSource) requestEvent.getSource(),
							getAllStatus(requestEvent.getInstanceID()));
		}
	}

	protected PositionInfo getPositionInfo(int instanceID) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 请求当前的所有播放状态
	 * @param instanceID 
	 * @return
	 * 		com.oazon.moco.lan.core.http.bean.AllSatus
	 * 		对象，包含所有播放状态
	 */
	protected MediaStateInstance getAllStatus(int instanceID) {
		Log.i(TAG, "RequestEventListener==getAllStatus");
		return null;
	}

	/**
	 * 请求得到当前的播放模式
	 * @return
	 * 		 com.oazon.moco.bean.PlayMode;的常量
	 */
	protected String getPlayMode() {
		Log.i(TAG, "RequestEventListener==getPlayMode");
		return "";
	}

	/**
	 * 请求得到当前歌曲的是播放目录
	 * @return
	 * 		
	 */
	protected String getCategory() {
		Log.i(TAG, "RequestEventListener==getCategory");
		return "";
	}

	/**
	 * 请求得到当前歌曲的播放信息
	 * @return
	 * 	com.oazon.moco.lan.core.http.bean.SongInfo
	 * 	对象
	 */
	protected SongInfo getSongInfo() {
		Log.i(TAG, "RequestEventListener==getSongInfo");
		return null;
	}

	/**
	 * 请求得到当前的音量
	 * @param instanceID 
	 * @return
	 * 【0~31】
	 */
	protected ResponseVolume getVolume(int instanceID) {
		Log.i(TAG, "RequestEventListener==getVolume");
		return null;
	}

	/**
	 * 请求得到当前的版本信息
	 * @param version
	 * @return
	 * 		
	 */
	protected ZoneInfo getVersion(ZoneInfo zoneInfo) {
		Log.i(TAG, "RequestEventListener==getVersion" + zoneInfo.getSoftwareVersion());
		return null;

	}
	
	/**
	 * 请求得到当前的播放状态
	 * @return
	 *		 com.oazon.moco.bean.PlayStatus的常量
	 */
	protected String getPlayStatus(){
		Log.i(TAG, "RequestEventListener==getPlayStatus");
		return "";
	}

}
